<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>绘制坐标系</title>
</head>

<body>
  <div class="container">
    <canvas id="canvas" height="400" width="600"></canvas>
  </div>
</body>

<script>
  var canvas = document.getElementById('canvas'); //获取canvas标签
  var ctx = canvas.getContext('2d'); //获取上下文

  canvas.style.border = '2px solid #000';

  //画笔起点
  var x0 = 100;
  var y0 = 380;
  var maxHeight = 390;
  var arrowWidth = 10; //箭头宽度

  //绘制x轴
  ctx.beginPath();
  ctx.strokeStyle = 'blue';
  ctx.moveTo(x0, y0);
  ctx.lineTo(500, 380);

  ctx.lineTo(500 - arrowWidth, 380 - arrowWidth);
  ctx.moveTo(500, 380);
  ctx.lineTo(500 - arrowWidth, 380 + arrowWidth);
  ctx.stroke();

  //绘制y轴
  ctx.beginPath();
  ctx.moveTo(x0, y0);
  ctx.lineTo(100, 0);
  ctx.lineTo(100 - arrowWidth, arrowWidth);
  ctx.moveTo(100, 0);
  ctx.lineTo(100 + arrowWidth, arrowWidth);
  ctx.stroke();

  //绘制线段
  var data = [0.4, 0.5, 0.3, 0.8, 0.4, 0.6]; //假数据
  var pointWidth = 380 / (data.length + 1);
  ctx.beginPath();
  ctx.strokeStyle = 'red';
  for (var i = 0; i < data.length; i++) {
    var x = x0 + (i + 1) * pointWidth;
    var y = y0 - data[i] * maxHeight;
    ctx.lineTo(x, y)
  }
  ctx.stroke();
</script>
<style>
   .container{
      margin:0 auto;
      width:800px;
    }
</style>
</html>